package com.yequan.work;

import lombok.extern.slf4j.*;

import java.text.*;
import java.util.*;

/**
 * @author yequan
 * @date 2021/03/03 19:20
 **/
@Slf4j
public class InvalidPlanStartTimeCheckUtil {

    /**
     * 处理修改的出发时间是否合规
     * 如果planStartTime为空表明没有修改过出发时间
     * 否则表示修改过，此时需要对修改过的时间进行合规校验
     *
     * @param planStartTime
     * @param rideType
     * @return
     */
    public static String getValidPlanStartTime(String planStartTime, int rideType) {
        if (null == planStartTime) {
            return null;
        }
        try {
            Date planStartTimeDate = DateUtil.string2Date(planStartTime);
            if (7 == rideType) {
                if (planStartTimeDate.getHours() >= 23 || planStartTimeDate.getHours() < 5) {
                    return null;
                }
            } else {
                if (planStartTimeDate.getHours() >= 1 && planStartTimeDate.getHours() < 5) {
                    return null;
                }
            }
            return planStartTime;
        } catch (ParseException e) {
            log.error("getValidPlanStartTime parse date error!", e);
            return null;
        }
    }

    public static void main(String[] args) {
        String pl = "20210304043500";
        String validPlanStartTime = getValidPlanStartTime(pl, 3);
        pl = getValidPlanStartTime(pl, 3);
        System.out.println("new:" + validPlanStartTime);
        System.out.println("pl:" + pl);
    }

}
